# -*- coding: utf-8 -*-

# __date:       2021/6/16
# __author:     YangChao
# __function:

from core.log import iqlog
from core.experiment.top_calibration import TopCalibration


class EnumerationCalibration(TopCalibration):

    def run(self):
        iqlog.info(f"--- LO:{self.f_lo} RF:{self.sweep_rf[0]}-{self.sweep_rf[-1]} {self.__class__.__name__} start ---")
        for f_rf in self.rf_list:
            print(f'---------- RF = {f_rf} IQ enumeration calibration start ... ----------')
            self._init_inst(f_rf)
            param = [f_rf, self.f_lo]
            self._leak_calibration(self.scope_list[0], self.step_list[0],
                                   self.scope_list[0], self.step_list[0], True)
            param_dac = self._leak_calibration(self.scope_list[1], self.step_list[1],
                                               self.scope_list[2], self.step_list[2], False)
            param_dc = self._leak_calibration(self.scope_list[3], self.step_list[3],
                                              self.scope_list[3], self.step_list[3], True)
            param.extend(param_dac)
            param.extend(param_dc)
            self.result.append(param)
            print(f'----------- RF = {f_rf} IQ enumeration calibration end ... -----------\n')
        self._save_result()
